package designPattern.singleton单例模式.demo07;

public class SingletonDemo07 {

    public static void main(String[] args) {
        Singleton instance1 = Singleton.INSTANCE;
        Singleton instance2 = Singleton.INSTANCE;
        instance1.sayOk();
        System.out.println(instance1 == instance2);
        System.out.println(instance1.hashCode());
        System.out.println(instance2.hashCode());
    }
}

// 单例模式-枚举: 推荐使用
enum Singleton {
    INSTANCE;
    public void sayOk() {
        System.out.println("ok");
    }
}

